// Car/ Rock View

(function( window, undefined ) {

var Rock = Class({
	name: "Rock",
	parent: "View",
	constructor: function() {
		var _$object = $("<div class='rock'></div>");
		var _point = 0;
		var _info = null;
		
		return {
			__construct: function( info, point ) {
				console.log( this, "__construct" );
				
				_info = info;
				_point = point;
				
				_$object.css( "left", 600 );
			},
			
			destroy: function() {
				
			},
			
			object: function() {
				return _$object;
			},
			
			hit: function( car ) {
				var x = parseInt( _$object.css("left") );
				
				var carX = parseInt( car.object().css( "left" ) );
				var carWidth = car.object().width();
				var bottom = parseInt( car.object().css( "bottom" ) );
				
				if ( x >= carX && x <= ( carX + carWidth ) ) {
					if ( ( bottom - _$object.height() - 20 ) < 0 ) { 
						return true;
					};
				};
				
				return false;
			},
			
			flow: function() {
				var x = parseInt( _$object.css("left") );
				var speed = _info.speed();
				
				x = x - speed;
				
				_$object.css( "left", x );
				
				return ( x < ( _$object.width() * -1 ) ) ? false : true;
			}
		}
	}
});

Class.View.Rock = Rock;

})();